import { createRouter,createWebHistory } from 'vue-router'
import VueCookies from 'vue-cookies';
// 定义路由数组
const routes = [
    {
        name: '登录',
        path: '/login',
        component: () => import('../views/Login.vue'),
    },
    {
        name: '框架页',
        path: '/',
        component: () => import('../views/Framework.vue'),
        redirect: "/blog/list",
        children: [
            {
                path: "blog/list",
                name: "博客管理",
                component: ()=> import('../views/blog/List.vue'),
            },
            {
                path: "blog/category",
                name: "分类管理",
                component: ()=> import('../views/blog/Category.vue'),
            },
            {
                path: "special/list",
                name: "专题管理",
                component: ()=> import('../views/special/SpecialList.vue'),
            },
            {
                path: "dataAnalysis/traffic",
                name: "流量分析",
                component: ()=> import('../views/dataAnalysis/Traffic.vue'),
            },
            {
                path: "dataAnalysis/text",
                name: "文章数据",
                component: ()=> import('../views/dataAnalysis/Text.vue'),
            },
            {
                path: "setting/me",
                name: "个人信息设置",
                component: ()=> import('../views/setting/Me.vue'),
            },
            {
                path: "setting/users",
                name: "博客成员",
                component: ()=> import('../views/setting/Users.vue'),
            },
            {
                path: "setting/sysSetting",
                name: "系统设置",
                component: ()=> import('../views/setting/SysSetting.vue'),
            },
            {
                path: "recovery/list",
                name: "回收站",
                component: ()=> import('../views/recovery/List.vue'),
            },
        ]
    }
];
// 创建实例
// 这里通过createRouter方法创建实例，使用的模式不是同通过mode来定义
const router = createRouter({
    routes,
    history: createWebHistory(),
})

router.beforeEach((to,from,next) => {
    const userInfo = VueCookies.get("userInfo");
    if(!userInfo&&to.path!='/login'){
        router.push("/login");
    }
    next();
});

// 导出实例
export default router